import { useState, useEffect } from 'react';
import i18n from 'i18next';

export type languageType = 'en' | 'ch';

const useLanguage = (props: languageType) => {
  const [lang, setLang] = useState(props);

  useEffect(() => {
    setThemeFn(lang);
  }, [lang]);

  const setThemeFn = (la: languageType) => {
    console.log('bianhua', la);

    i18n.changeLanguage(la);
  };

  const changeLanguage = (lang: languageType) => {
    console.log('change');

    setLang(lang);
  };

  return { changeLanguage };
};

export default useLanguage;
